﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Objects;
using WISD.CarFriend.Model;
using WISD.Common;

namespace WISD.CarFriend.BLL.Web
{
    public class IntroductionManageModule
    {
        /// <summary>
        /// 获取所有页面信息
        /// state:1 未删除
        /// state:0 已删除
        /// </summary>
        /// <returns></returns>
        public DataTable GetAllIntroductions()
        {
            using (CarFriendDBContext edm = new CarFriendDBContext())
            {
                return EFHelper.ListToDataTable<T_CF_Web_Introduction>(edm.T_CF_Web_Introduction.Where(p => p.State == 1).ToList());
            }
        }


        /// <summary>
        /// 根据ID查找页面信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public T_CF_Web_Introduction GetIntroductionByID(int id)
        {
            using (CarFriendDBContext edm = new CarFriendDBContext())
            {
                return edm.T_CF_Web_Introduction.FirstOrDefault(p => p.IntroductionID == id);
            }
        }


        /// <summary>
        /// 修改页面信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="title"></param>
        /// <param name="webContent"></param>
        /// <param name="updaterID"></param>
        public void UpdateIntroduction(int id, string title, string webContent, int updaterID)
        {
            using (CarFriendDBContext edm = new CarFriendDBContext())
            {
                T_CF_Web_Introduction introduction = edm.T_CF_Web_Introduction.FirstOrDefault(p => p.IntroductionID == id);
                introduction.Title = title;
                introduction.WebContent = webContent;
                introduction.UpdaterID = updaterID;
                introduction.UpdateTime = DateTime.Now;
                edm.SaveChanges();
            }
        }

    }
}

